<?php

namespace app\Api\controller;

use app\common\business\SPartners as SPartnersBus;
use app\common\lib\Str;

class Partners extends ApiBase
{
    public function partnerList(){
        $where = [];
        // 获取分页参数
        $page = $this->request->param('pageNum', 1);
        $limit = $this->request->param('pageSize', 10);
        $partnersName = $this->request->get("partnersName","");
        if ($partnersName) {
            $where[] = ['a.partners_name', 'like', '%'.$partnersName.'%'];
        }
        $where[] = ["a.del_flag", "=", '0'];
        $where[] = ["a.status", "=", '0'];
        try {
            $field = "a.partners_id,a.partners_name,a.contact,a.contact_phone,a.province,a.city,a.county,b.partners_category_name";
            $menuData = (new SPartnersBus())->getNormalPartners($where,$field,$limit,$page);
            if($menuData['data']){
                $regionsData = file_get_contents(public_path()."static/region/region.json");
                $regionsArrData = json_decode($regionsData,true)['data'];
                foreach ($menuData['data'] as $k=>$v){
                    $menuData['data'][$k]['province_name'] = (new Str())->getRegionNameByPid($v['province'],$regionsArrData);
                    $menuData['data'][$k]['city_name'] = (new Str())->getRegionNameByPid($v['city'],$regionsArrData);
                    $menuData['data'][$k]['county_name'] = (new Str())->getRegionNameByPid($v['county'],$regionsArrData);
                }
            }
        }catch (\Exception $e){
            $menuData = [];
        }
        return show(config("status.success"),"合作商列表",$menuData);
    }
}
